package com.lh.pospi.x_store.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.lh.pospi.x_store.R;
import com.qmuiteam.qmui.widget.QMUIProgressBar;
import com.vondear.rxui.view.dialog.RxDialog;

public class ProgressDialog extends RxDialog {

    private QMUIProgressBar progress_bar;

    public ProgressDialog(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public ProgressDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public ProgressDialog(Context context) {
        super(context);
        initView();
    }


    public void setProgress(int progress) {
        progress_bar.setProgress(progress);
    }
    public void setMax(int max) {
        progress_bar.setMaxValue(max);
    }
    private void initView() {
        View dialogView = LayoutInflater.from(this.getContext()).inflate(R.layout.layout_progress, (ViewGroup)null);
        progress_bar = dialogView.findViewById(R.id.progress_bar);
        progress_bar.setQMUIProgressBarTextGenerator(new QMUIProgressBar.QMUIProgressBarTextGenerator() {
            @Override
            public String generateText(QMUIProgressBar progressBar, int value, int maxValue) {
                if (value >= maxValue) {
                    value = maxValue;
                }

                return (int)(((float)value/(float)maxValue)*100)+"%";
            }
        });
        this.setContentView(dialogView);
    }
}
